const footer = document.querySelector("footer");
const main = document.querySelector("main");

let wordCount = footer.querySelector(".word-count");
let lineNumber = footer.querySelector(".line-number");
let text = main.querySelector(".left-InputArea").querySelector("#texts");

// 字数
text.onkeydown = function(e) {            
  text.onkeyup = function(e) {       
    
    if(e.key === "Enter") {
      let j = 0;
      for(let i = 0; i < text.value.length; i++) {
        if(text.value[i] === "\n") { j++; }
      }   
      lineNumber.innerHTML = "行数：" + j;   
    }else if(e.key === "Backspace") {
      let j = 1;
      for(let i = 0; i < text.value.length; i++) {
        if(text.value[i] === "\n") { j++; }
      }         
      lineNumber.innerHTML = "行数：" + j;
    }
    // console.log(e.key)
    wordCount.innerHTML = "字数：" + text.value.length;    
  }
}


